﻿<UserControl x:Class="DeltaGroup.WheelOfJeopardy.UI.Screens.ChallengeEditor"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:Commands="clr-namespace:DeltaGroup.WheelOfJeopardy.UI.Commands"
             mc:Ignorable="d"  
             d:DesignHeight="300" d:DesignWidth="300" Background="{StaticResource ScreenBackgroundBrushKey}">
    <UserControl.CommandBindings>
        <CommandBinding Command="Commands:WoJCommands.SaveChallenge" CanExecute="CanSave"  />
    </UserControl.CommandBindings>

    <ScrollViewer>
        <AdornerDecorator>
            <DockPanel>
                <Grid DockPanel.Dock="Top">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>

                    <TextBlock Text="Choose a pre-existing game file to edit:" HorizontalAlignment="Right" Grid.Row="0" Grid.Column="0" Margin="10,5" />
                    <ComboBox  ItemsSource="{Binding ChallengeFiles}" HorizontalAlignment="Left" Grid.Row="0" Grid.Column="1" Width="150" Margin="10,5,0,10" >
                        <ComboBox.SelectedValue>
                            <Binding Path="SelectedChallengeFile" />
                        </ComboBox.SelectedValue>
                    </ComboBox>

                    <TextBlock Text="- OR -" Grid.Row="1" HorizontalAlignment="Center" />

                    <TextBlock Text="Create a game of new categories and challenges:" HorizontalAlignment="Right" Grid.Row="2" Grid.Column="0" Margin="10,5" />
                    <TextBox Grid.Row="2" Grid.Column="1" Width="300" Margin="10,5,0,10" HorizontalAlignment="Left">
                        <TextBox.Text>
                            <Binding Path="NewChallengeFile" />
                        </TextBox.Text>
                    </TextBox>
                </Grid>

                <StackPanel DockPanel.Dock="Top" >
                    <TextBlock Text="Jeopardy" Style="{StaticResource EditorSection}" />
                    <ItemsControl x:Name="jeopardyCategories" 
                          ItemsSource="{Binding Path=JeopardyCategories, BindsDirectlyToSource=True, NotifyOnSourceUpdated=True, Mode=TwoWay, NotifyOnValidationError=True}" 
                          DockPanel.Dock="Top">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <GroupBox Margin="5" Padding="10">
                                    <GroupBox.Header>
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock Text="Category:" Style="{StaticResource EditorLabel}" />
                                            <TextBox Text="{Binding Path=Title, BindsDirectlyToSource=True, NotifyOnValidationError=True, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" Width="200" />
                                        </StackPanel>
                                    </GroupBox.Header>
                                    <ItemsControl
                                  ItemsSource="{Binding Path=Challenges, BindsDirectlyToSource=True, NotifyOnSourceUpdated=True, Mode=TwoWay, NotifyOnValidationError=True}" >
                                        <ItemsControl.ItemTemplate>
                                            <DataTemplate>
                                                <Grid>
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition Width="110" />
                                                        <ColumnDefinition Width="Auto" />
                                                        <ColumnDefinition Width="*" />
                                                        <ColumnDefinition Width="Auto" />
                                                        <ColumnDefinition Width="*" />
                                                    </Grid.ColumnDefinitions>
                                                    <TextBlock Grid.Column="0" HorizontalAlignment="Left" Margin="0,5,0,0">
                                                        <TextBlock.Text>
                                                            <MultiBinding StringFormat="Question {0} ({1})">
                                                                <Binding Path="Index" />
                                                                <Binding Path="Point" />
                                                            </MultiBinding>
                                                        </TextBlock.Text>
                                                    </TextBlock>
                                                    <TextBlock Grid.Column="1" Text="Challenge: " Style="{StaticResource EditorLabel}" />
                                                    <TextBox Grid.Column="2" Margin="5,5">
                                                        <TextBox.Text>
                                                            <Binding Path="Prompt" UpdateSourceTrigger="PropertyChanged" ValidatesOnDataErrors="True" NotifyOnValidationError="True">
                                                            </Binding>
                                                        </TextBox.Text>
                                                    </TextBox>
                                                    <TextBlock Grid.Column="3"  Text="Response: " Style="{StaticResource EditorLabel}" />
                                                    <TextBox Grid.Column="4" Margin="5,5">
                                                        <TextBox.Text>
                                                            <Binding Path="ExpectedResponse" UpdateSourceTrigger="PropertyChanged" ValidatesOnDataErrors="True" NotifyOnValidationError="True">
                                                            </Binding>
                                                        </TextBox.Text>
                                                    </TextBox>
                                                </Grid>
                                            </DataTemplate>
                                        </ItemsControl.ItemTemplate>
                                    </ItemsControl>
                                </GroupBox>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                </StackPanel>

                <StackPanel DockPanel.Dock="Top">
                    <TextBlock Text="Double Jeopardy" Style="{StaticResource EditorSection}" />
                    <ItemsControl x:Name="doubleJeopardyCategories" ItemsSource="{Binding Path=DoubleJeopardyCategories, BindsDirectlyToSource=True, NotifyOnSourceUpdated=True, Mode=TwoWay, NotifyOnValidationError=True}" 
                          DockPanel.Dock="Top">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <GroupBox Margin="5" Padding="10">
                                    <GroupBox.Header>
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock Text="Category:" Style="{StaticResource EditorLabel}" />
                                            <TextBox Text="{Binding Path=Title, BindsDirectlyToSource=True, NotifyOnValidationError=True, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" Width="200" />
                                        </StackPanel>
                                    </GroupBox.Header>
                                    <ItemsControl
                                  ItemsSource="{Binding Path=Challenges, BindsDirectlyToSource=True, NotifyOnSourceUpdated=True, Mode=TwoWay, NotifyOnValidationError=True}" >
                                        <ItemsControl.ItemTemplate>
                                            <DataTemplate>
                                                <Grid>
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition Width="110" />
                                                        <ColumnDefinition Width="Auto" />
                                                        <ColumnDefinition Width="*" />
                                                        <ColumnDefinition Width="Auto" />
                                                        <ColumnDefinition Width="*" />
                                                    </Grid.ColumnDefinitions>
                                                    <TextBlock Grid.Column="0" HorizontalAlignment="Left" Margin="0,5,0,0">
                                                    <TextBlock.Text>
                                                        <MultiBinding StringFormat="Question {0} ({1})">
                                                            <Binding Path="Index" />
                                                            <Binding Path="Point" />
                                                        </MultiBinding>
                                                    </TextBlock.Text>
                                                    </TextBlock>
                                                    <TextBlock Grid.Column="1" Text="Challenge: " Style="{StaticResource EditorLabel}" />
                                                    <TextBox Grid.Column="2" Margin="5,5">
                                                        <TextBox.Text>
                                                            <Binding Path="Prompt" UpdateSourceTrigger="PropertyChanged" ValidatesOnDataErrors="True" NotifyOnValidationError="True">
                                                            </Binding>
                                                        </TextBox.Text>
                                                    </TextBox>
                                                    <TextBlock Grid.Column="3" Text="Response: " Style="{StaticResource EditorLabel}" />
                                                    <TextBox Grid.Column="4" Margin="5,5">
                                                        <TextBox.Text>
                                                            <Binding Path="ExpectedResponse" UpdateSourceTrigger="PropertyChanged" ValidatesOnDataErrors="True" NotifyOnValidationError="True">
                                                            </Binding>
                                                        </TextBox.Text>
                                                    </TextBox>
                                                </Grid>
                                            </DataTemplate>
                                        </ItemsControl.ItemTemplate>
                                    </ItemsControl>
                                </GroupBox>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                </StackPanel>

                <StackPanel  DockPanel.Dock="Top" >
                    <TextBlock Text="Final Jeopardy" Style="{StaticResource EditorSection}" />
                    <Grid DataContext="{Binding FinalJeopardyChallenge}">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <TextBlock Grid.Column="0" Text="Challenge: " Style="{StaticResource EditorLabel}" />
                        <TextBox Grid.Column="1" Margin="5,5">
                            <TextBox.Text>
                                <Binding Path="Prompt" UpdateSourceTrigger="PropertyChanged" ValidatesOnDataErrors="True" NotifyOnValidationError="True">
                                </Binding>
                            </TextBox.Text>
                        </TextBox>
                        <TextBlock Grid.Column="2" Text="Response: " Style="{StaticResource EditorLabel}" />
                        <TextBox Grid.Column="3" Margin="5,5">
                            <TextBox.Text>
                                <Binding Path="ExpectedResponse" UpdateSourceTrigger="PropertyChanged" ValidatesOnDataErrors="True" NotifyOnValidationError="True">
                                </Binding>
                            </TextBox.Text>
                        </TextBox>
                    </Grid>
                </StackPanel>

                <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="8,15">
                    <Button Content="Back" Command="Commands:WoJCommands.Menu" Margin="10,5" Height="30" Width="75" />
                    <Button Content="Finish" Command="Commands:WoJCommands.SaveChallenge" CommandParameter="{Binding}" Margin="10,5" Height="30" Width="75" />
                </StackPanel>

            </DockPanel>
        </AdornerDecorator>
    </ScrollViewer>
</UserControl>
